﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Eventbrite;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace EventbriteSample
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        EventbriteClient eventbrite;

        public MainPage()
        {
            this.InitializeComponent();
            if (string.IsNullOrEmpty(AppKeys.kEventbriteAppKey))
                throw new NotImplementedException("You need to add your keys");
            eventbrite = new EventbriteClient(AppKeys.kEventbriteAppKey);
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void clickMeButton_Click(object sender, RoutedEventArgs e)
        {
            Auth();
        }

        private async Task Auth()
        {
            var result = await eventbrite.AuthorizeAsync("http://jaykimble.net");
            Debug.WriteLine("authd: " + result);
            if (result)
            {
                runTests();
            }
        }

        private async Task runTests()
        {
            var userId = "2813326";
            var eventId = "3571098251";
            var userEmail = "jkimble@intradynamics.net";
            var result = await eventbrite.GetUser();
            Debug.WriteLine("\n!!!!!!!!!{0}: \n{1}", "GetUser", result);

            result = await eventbrite.ListUserEvents(userEmail, doNotDisplay: new[] { "description", "venue", "logo", "style", "organizer", "tickets" }, sortOrder: SortOrder.Desc);
            Debug.WriteLine("\n!!!!!!!!!{0}: \n{1}", "ListUserEvents", result);

            result = await eventbrite.ListUserTickets();
            Debug.WriteLine("\n!!!!!!!!!{0}: \n{1}", "ListUserTickets", result);

            result = await eventbrite.ListOrganizersForUser();
            Debug.WriteLine("\n!!!!!!!!!{0}: \n{1}", "ListUserOrganizers", result);

        }
    }
}
